<template>
	<gui-page ref="guiPage" :customHeader="true">
		<template v-slot:gHeader>
			<nav-bar-custom left-icon="left" :title="$t('finishedInventory.inventoryParticulars')"
				:rightText="$t('distributedEnter.scanRecord')" @clickRight="clickRight"></nav-bar-custom>
		</template>
		<template v-slot:gBody>

			<!--最上面的搜索内容-->
			<view class="distributed">
				<!-- 库存信息-->
				<view class="custom-form-card">
					<view class="custom-card-itemOne addflex">
						<text class="item-info-title itemflex">{{ $t('finishInventory.mesTotalPieces') }}：<text
								style="color: #333;">{{ data.billCodeInfo.mesTotalPieces }}</text></text>
						<text class="item-info-title itemflex">{{ $t('finishInventory.K3TotalPieces') }}：<text
								style="color: #333;">{{ data.billCodeInfo.K3TotalPieces }}</text></text>
					</view>

					<view class="custom-card-itemOne addflex">
						<!-- <text class="item-info-title itemflex">MES总托数：<text style="color: #333;">222</text></text> -->
						<text class="item-info-title itemflex">{{ $t('finishInventory.mesTotalPallets') }}：<text
								style="color: #333;">{{ data.billCodeInfo.mesTotalPallets }}</text></text>
						<text class="item-info-title itemflex">{{ $t('finishInventory.K3TotalPallets') }}：<text
								style="color: #333;">{{ data.billCodeInfo.K3TotalPallets }}</text></text>
					</view>
					<view class="custom-card-itemOne addflex">
						<text class="item-info-title itemflex">{{ $t('finishInventory.TotalCheckedPallets') }}：<text
								style="color: #333;">{{ data.billCodeInfo.TotalCheckedPallets }}</text></text>
						<text class="item-info-title itemflex">{{ $t('finishInventory.totalUncheckedPallets') }}：<text
								style="color: #333;">{{ data.billCodeInfo.totalUncheckedPallets }}</text></text>
					</view>
				</view>
				<!-- 填写内容 -->
				<view class="custom-form-card">
					<view class="custom-card-title">
						<text class="title-line"></text>
						{{ $t('distributedEnter.barcodeScan') }}
					</view>
					<view class="custom-card-scan">
						<uni-easyinput class="uni-mt-5" suffixIcon="scan" v-model="data.scanValue"
							:placeholder="$t('stockManage.pleaseScanCode')" @confirm="confirm" @iconClick="iconClick">
						</uni-easyinput>
					</view>
					<view class="custom-card-itemTwo" style="padding: 5rpx 0;">
						<text class="item-info-title">{{ $t('distributedEnter.materialCode') }}：</text>
						<comboGrid requestUrl="/mes/basMaterial/getPageSetPDA" v-model="data.materialCode"
							style="flex:1" :requestParam="data.materialParam" inputKey="materialName"
							:placeholder="$t('distributedEnter.placeholderTextChoose')" gridPlaceholder="输入代码或者名称筛选"
							:column="data.columnName.column" bindValue="materialCode" @setClick="getMaterialClick">
						</comboGrid>
						<uni-icons class="iconDelete" type="close" v-if="data.materialCode" size="18" color="#999"
							@click="handelMaterialClear"></uni-icons>
					</view>
					<view class="custom-card-itemTwo" style="padding: 5rpx 0;">
						<text class="item-info-title" style="width:180rpx">{{ $t('distributedOut.location') }}：</text>
						<storageBin :ignoreLocationCode="data.ignoreLocationCode" class="gui-text-right"
							requestUrl="/wms/wmsLocation/getIsUsePageSetByFG" :requestParam="data.requestParam"
							:placeholder="$t('distributedEnter.placeholderTextChoose')"
							:locationUseList="data.locationUseList" v-model="data.locationCode"
							@setClick="getLocationClick" style="flex:1"></storageBin>
						<uni-icons class="iconDelete" type="close" v-if="data.locationCode.length" size="18"
							color="#999" @click="handelClear"></uni-icons>
					</view>
					<view class="custom-card-itemTwo" style="padding: 5rpx 0;">
						<text style="width:61% ">
							<text class="item-info-title">{{ $t('finishInventory.scanTotalPcs') }}：</text>
							<text style="margin-left: 20rpx;">{{ data.scanTotalPcs }}</text>
						</text>
						<text style="flex: 1;text-align: left;">
							<text class="item-info-title" style="width:220rpx;text-align: left;">{{
								$t('finishInventory.scanTotalMaterialCount') }}：</text>
							<text>{{ data.scanTotalMaterialCount }}</text>
						</text>
					</view>
				</view>
				<!--结果区-->
				<scroll-view :show-scrollbar="false" :scroll-y="true" class="scroll">
					<!--条码维度-->
					<template v-if="data.searchType == 1">
						<view class="custom-form-card" v-for="(x, i) in data.barcodeData" :key="i">
							<uni-collapse v-model="data.value">
								<uni-collapse-item titleBorder="true" :show-animation="true" :name="'' + i">
									<template v-slot:title>
										<view class="custom-card-itemOne" style="padding: 10px 0">
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('distributedEnter.barcode')
													}}：</text>{{ x.barcode }}
												<uni-tag :mark="true" :text="$t('finishInventory.checked')"
													type="primary" size="default" v-if="x.ckeckFlag == 'Y'" />
												<uni-tag :mark="true" :text="$t('finishInventory.unchecked')"
													type="primary" size="default" v-else />
											</view>
										</view>
									</template>
									<view class="content" style="margin-bottom: 20rpx;">
										<view class="custom-card-itemOne" style="margin-top: 10px">
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('distributedEnter.materialCode')
													}}：</text>{{ x.materialCode }}
											</view>
										</view>
										<view class="custom-card-itemOne">
											<text class="item-info-title">{{ $t('distributedEnter.materialName')
												}}：</text>{{ x.materialName }}
										</view>
										<view class="custom-card-itemOne">
											<text class="item-info-title">{{ $t('distributedEnter.materialSpec')
												}}：</text>{{ x.materialSpec }}
										</view>
										<view class="custom-card-itemOne">
											<text class="item-info-title">{{ $t('distributedEnter.uom') }}：</text>{{
												x.unit }}
										</view>

										<view class="custom-card-itemOne">
											<text class="item-info-title">{{ $t('distributedOut.location') }}：</text>{{
												data.locationCode
											}}
										</view>
										<view class="custom-card-itemOne">
											<view class="card-item-50"><text class="item-info-title">{{
												$t('distributedEnter.qty') }}：</text>
												<uni-tag :text="x.stockQty" type="success" />
												<!--{{x.stockQty}}-->
											</view>
											<!--<view class="card-item-50">-->
											<!--	<text class="item-info-title">{{$t('pageTranslation.chekStatus')}}：</text>-->
											<!--	<view class="btnSuccess" v-if="x.ckeckFlag=='Y'">{{$t('finishInventory.checked')}}</view>-->
											<!--	<view class="btnError" v-else>{{$t('finishInventory.unchecked')}}</view>-->
											<!--</view>-->
										</view>
										<view class="divider"></view>
										<view class="custom-card-itemOne">
											<view style="margin-left: 73%;">
												<view class="btnCancel" v-if="x.ckeckFlag == 'Y'"
													@click="HandUnCheckPda(x.barcode)">
													{{ $t('finishInventory.cancel') }}</view>
												<view class="btnPanDian" v-else @click="HandCheckPda(x.barcode)">
													{{ $t('finishInventory.check') }}</view>
											</view>
										</view>
									</view>
								</uni-collapse-item>
							</uni-collapse>
						</view>
					</template>

					<!--物料维度-->
					<template v-if="data.searchType == 2">
						<view class="custom-form-card" v-for="(x, i) in data.materialData" :key="i">
							<uni-collapse v-model="data.value">
								<uni-collapse-item titleBorder="true" :show-animation="true" :name="'' + i">
									<template v-slot:title>
										<view class="custom-card-itemOne" style="margin: 10px 0 5px 9px">
											<text class="item-info-title">{{ $t('distributedEnter.materialCode')
												}}：</text>
											<uni-tag :mark="true" :text="x.materialCode" type="primary"
												size="default" />

											<!--{{x.materialCode}}-->
										</view>
									</template>
									<view class="content" style="margin-bottom: 20rpx;">



										<view class="custom-card-itemOne">
											<text class="item-info-title">{{ $t('distributedEnter.materialName')
												}}：</text>{{ x.materialName }}
										</view>
										<view class="custom-card-itemOne">
											<text class="item-info-title">{{ $t('distributedEnter.materialSpec')
												}}：</text>{{ x.materialSpec }}
										</view>
										<view class="custom-card-itemOne">
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('finishInventory.scanTotalPcs')
													}}：</text>{{ x.totalPallets }}
											</view>
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('distributedEnter.uom') }}：</text>{{
													x.unit }}
											</view>
										</view>
										<view class="custom-card-itemOne">
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('finishInventory.checkedQty')
													}}：</text>
												<uni-tag :text="x.countCheckQty || '0'" type="success" />
												<!--{{x.countCheckQty}}-->
											</view>
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('finishInventory.uncheckedQty')
													}}：</text>
												<uni-tag :text="x.countNotCheckQty || '0'" />

												<!--{{x.countNotCheckQty}}-->
											</view>
										</view>
										<view class="divider"></view>
										<view class="custom-card-itemOne flexRight">
											<view>
												<view class="btnSuccess" style="margin-right: 10rpx;"
													@click="clickView(x.materialCode)">
													{{ $t('finishInventory.view') }}</view>
												<view class="btnCancel" v-if="x.ckeckFlag == 'Y'"
													@click="HandUnCheckPda(x.materialCode)">
													{{ $t('finishInventory.cancel') }}</view>
												<view class="btnPanDian" v-else @click="HandCheckPda(x.materialCode)">
													{{ $t('finishInventory.check') }}</view>
											</view>
										</view>
									</view>
								</uni-collapse-item>
							</uni-collapse>
						</view>
					</template>
					<!--库存维度-->
					<template v-if="data.searchType == 3">
						<view class="custom-form-card" v-for="(x, i) in data.locationData" :key="i">
							<uni-collapse v-model="data.value">
								<uni-collapse-item titleBorder="true" :show-animation="true" :name="'' + i">
									<template v-slot:title>
										<view class="custom-card-itemOne" style="margin: 10px 0 5px 0">
											<text class="title-line"></text>
											<view class="card-item-40 ">
												<text class="item-info-title">{{ $t('finishedInventory.warehouseCode')
													}}：</text>{{ x.warehouseCode }}
											</view>
											<view class="card-item-60">
												<text class="item-info-title">{{ $t('finishInventory.locationCode')
													}}：</text>{{ x.locationCode }}
											</view>
										</view>
									</template>
									<view class="content" style="margin-bottom: 20rpx;">

										<view class="custom-card-itemOne">
											<text class="item-info-title">{{ $t('distributedEnter.materialCode')
												}}：</text>{{ x.materialCode }}
										</view>

										<view class="custom-card-itemOne">
											<text class="item-info-title">{{ $t('distributedEnter.materialName')
												}}：</text>{{ x.materialName }}
										</view>
										<view class="custom-card-itemOne">
											<text class="item-info-title">{{ $t('distributedEnter.materialSpec')
												}}：</text>{{ x.materialSpec }}
										</view>
										<view class="custom-card-itemOne">
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('finishInventory.scanTotalPcs')
													}}：</text>{{ x.totalPallets }}
											</view>
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('distributedEnter.uom') }}：</text>{{
													x.unit }}
											</view>
										</view>
										<!--<view class="custom-card-itemOne">-->
										<!--	<view class="card-item-50">-->
										<!--		<text class="item-info-title">{{$t('finishInventory.warehouseCode')}}：</text>{{x.warehouseCode}}-->
										<!--	</view>-->
										<!--	<view class="card-item-50">-->
										<!--		<text class="item-info-title">{{$t('finishInventory.locationCode')}}：</text>{{x.locationCode}}-->
										<!--	</view>-->
										<!--</view>-->
										<view class="custom-card-itemOne">
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('finishInventory.checkedQty')
													}}：</text>{{ x.countCheckQty }}
											</view>
											<view class="card-item-50">
												<text class="item-info-title">{{ $t('finishInventory.uncheckedQty')
													}}：</text>{{ x.countNotCheckQty }}
											</view>
										</view>
										<view class="divider"></view>
										<view class="custom-card-itemOne flexRight">
											<view>
												<view class="btnSuccess" style="margin-right: 10rpx;"
													@click="clickView(x.locationCode)">
													{{ $t('finishInventory.view') }}</view>
												<view class="btnCancel" v-if="x.ckeckFlag == 'Y'"
													@click="HandUnCheckPda(x.locationCode)">
													{{ $t('finishInventory.cancel') }}</view>
												<view class="btnPanDian" v-else @click="HandCheckPda(x.locationCode)">
													{{ $t('finishInventory.check') }}</view>
											</view>
										</view>
									</view>
								</uni-collapse-item>
							</uni-collapse>
						</view>
					</template>
				</scroll-view>

				<view class="page-bottom-boxtwo">
					<view class="page-bottomBtn bottomBtn-bgcolor-green" @click="handelCheck">
						{{ data.buttonText }}
					</view>
				</view>
			</view>

			<!-- 页面弹窗 -->
			<uni-popup ref="inputDialog" type="center" :mask-click="false">
				<view v-if="data.scanInfo" class="input-dialog-box">
					<view class="input-dialog-content">
						<view class="input-dialog-itembox" v-if="false">
							<view class="input-dialog-item">
								<text style="color:red;width:300rpx">{{ $t('pageTranslation.realInventoryQtyNew1')
									}}：</text><input class="input" type="number" style="color:red"
									v-model="data.scanInfo.stockQty"
									:placeholder="$t('pageTranslation.plsRealInventoryQty')" disabled="" />
							</view>
						</view>
						<view v-if="data.remarkBool" class="input-dialog-item addborder">
							<textarea class="textarea" :maxlength="-1" v-model="data.scanInfo.remarkText"
								style="height: 100px;" placeholder-style="color:#F76260"
								:placeholder="$t('pageTranslation.PlsInputRemarks')" />
						</view>
						<view class="input-dialog-itembox">
							<view class="input-dialog-item">
								{{ $t('pageTranslation.chekStatus') }}：{{ data.scanInfo.ckeckFlag == "Y" ? "check" :
									"unCheck"
								}}
							</view>
							<view class="input-dialog-item">
								{{ $t('distributedOut.barcode') }}：{{ data.scanInfo.barcode }}
							</view>
							<view class="input-dialog-item">
								{{ $t('distributedEnter.materialCode') }}：{{ data.scanInfo.materialCode }}
							</view>
							<view class="input-dialog-item">
								{{ $t('distributedEnter.materialName') }}：{{ data.scanInfo.materialName }}
							</view>
							<view class="input-dialog-item">
								{{ $t('distributedEnter.materialSpec') }}：{{ data.scanInfo.materialSpec }}
							</view>
							<view class="input-dialog-item">
								{{ $t('distributedEnter.uom') }}：{{ data.scanInfo.unit }}
							</view>
							<view class="input-dialog-item">
								{{ $t('distributedOut.location') }}：{{ data.scanInfo.locationCode }}
							</view>
							<!-- [[2022-10-27 SJM 改 -->
							<view class="input-dialog-item">
								{{ $t('pageTranslation.barcodeQty') }}：{{ data.scanInfo.stockQty
								}}<!-- {{data.scanInfo.currentQty}} -->
							</view>
							<view class="input-dialog-item">
								{{ $t('pageTranslation.thisCheckQty') }}：{{ data.scanInfo.checkQty
								}}<!-- {{data.scanInfo.currentQty}} -->
							</view>
							<!-- <view class="input-dialog-item">
					          {{$t('pageTranslation.barcodeStatus')}}：{{data.scanInfo.barcodeStatus}}
					        </view> -->
							<!-- 2022-10-27 SJM 改 ]] -->
						</view>
					</view>
					<view class="input-dialog-footer">
						<view class="input-dialog-button" @click="cancelFn">
							{{ $t('calendar.cancel') }}
						</view>
						<view class="input-dialog-button dialog-button-left" @click="scanConfirmFn">
							{{ $t('calendar.confirm') }}
						</view>
					</view>
				</view>
			</uni-popup>


		</template>
	</gui-page>
</template>

<script setup>
import {
	navigate,
	navigateBack
} from '@/utils/routerSkip.js';
import {
	ref,
	reactive,
	toRaw,
	watch,
	computed,
	onMounted
} from 'vue';
import storageBin from '@/components/storageBin.vue';
import comboGrid from "@/components/comboGrid";
import {
	onShow
} from '@dcloudio/uni-app';

import {
	TEST_URL,
	PROD_URL,
	IMG_BASE_URL
} from '@/constant/config.js'
import {
	TOKEN
} from '@/constant/index.js';
import {
	basPdaOperationLogFn
} from '@/utils/index.js';
import {
	OPERATION_COMMIT,
	OPERATION_SCAN
} from '@/constant/index.js'
import {
	getDataDictionaryFn,
	base64toFile
} from '@/utils/index.js'
//API引入
import {
	getInventoryTopInfo,
	selectWmsCheckStocked,
	checkFGStockSubmit,
	getTotalAndItems,
	getInventoryInfo,
	checkPDA
} from '@/api/api.js'
//扫描条码的引入
import pdaScan from '@/hooks/pdaScan.js'
import {
	useStore
} from "vuex";
import {
	forEach
} from '../../uni_modules/u-ajax/js_sdk/lib/utils';

//国际化引入
import {
	useI18n
} from 'vue-i18n';
import UniTag from "../../uni_modules/uni-tag/components/uni-tag/uni-tag.vue";
import VideoView from "../sopPage/videoView.vue";
const {
	t
} = useI18n();

const {
	scan
} = pdaScan()
let store = useStore();
// 接受来自父组件的传参 页面传值
const props = defineProps({
	id: String,
	billCode: String,
});

let inputDialog = ref(null)
//注册组件
components: {
	storageBin,
		comboGrid
}

let data = reactive({
	billCodeInfo: [], // 最上面的库存汇总信息
	id: props.id, // 上级界面传过来的id
	billCode: props.billCode, //上级界面传过来的billCode
	scanValue: '', //扫描信息
	scanInfo: null, //扫描的条码信息
	materialId: '', //物料id
	materialCode: '', //物料编码
	locationCode: '', //库位code
	locationId: '', //库位id
	locationName: '', //库位名称
	ignoreLocationCode: [],
	formData: '', // 签名信息
	scanTotalPcs: "", //扫描的总托数
	scanTotalMaterialCount: "", //扫描的物项总数

	barcodeData: [], //条码维度返回的信息
	materialData: [], //物料维度返回的信息
	locationData: [], //库位维度返回的信息
	locationCode: '',

	searchType: 1, //查询方式   1  条码维度   2 物料维度  3库位维度
	value: ['0'], //card的展开
	buttonText: t('finishInventory.signature'),

	//物料代码的传参
	materialParam: {
		text: '成品',
		materialCode: "",
		materialName: "", //物料代码,传给接口用的变量
	},
	// 库位的传参
	requestParam: {
		locationCode: ""
	},
	//物料代码的下拉选择器
	columnName: {
		column: [{
			label: t('distributedEnter.materialCode'),
			name: "materialCode",
		}, {
			label: t('distributedEnter.materialName'),
			name: "materialName",
		}]
	},
	// 库位的下拉选择器
	columnLocation: {
		column: [{
			label: t('JsInternational.volumnStockName'),
			name: "locationCode",
		}, {
			label: t('JsInternational.volumnStockOf'),
			name: "maxCapacity",
		}]
	},
})

// 页面显示就加载
onShow(() => {
	k3andMESTotal()
	selectMaterial()

})


// 获取库存数，通过盘点单号获取
const k3andMESTotal = () => {
	getInventoryTopInfo({
		billCode: data.billCode
	}).then(res => {
		if (res.status == 200) {
			data.billCodeInfo = res.data;
		}
	})
}


// 获取库存数总项
const TotalAndItems = () => {
	getTotalAndItems({
		billCode: data.billCode,
		barcode: data.scanValue,
		materialCode: data.materialCode,
		locationCode: data.locationCode
	}).then(res => {
		if (res.status == 200) {
			data.scanTotalPcs = res.dat?.totalPallets //总托数
			data.scanTotalMaterialCount = res.data?.totalMaterial //物项总数
		}
	})
}



onMounted(() => {
	uni.$on('scancodedate', (data) => {
		console.log('获取到的code：' + data.code)
		getCode(data.code, 'pda')
	})
})

// 用户调起相机扫码
const iconClick = async (type) => {
	console.log(type)
	if (type === 'suffix') {
		let code = await scan()
		getCode(code, 'scan')
	}
}
// 用户点击键盘上搜索
const confirm = () => {
	getCode(data.scanValue, 'keydown')
}

// 获取code，查询barcode信息
const getCode = (code, type) => {
	let parmes = { //根据barcode查询物料详情
		//barcode: data.scanValue,
		barcode: code,
		masterId: data.id,
		locationCode: '',
		materialCode: ''
	}
	selectWmsCheckStocked(parmes).then(res => {
		try {
			let inputParameter = JSON.stringify(parmes)
			let returnParameter = JSON.stringify(res)
			let operationPicture = '成品盘点'
			let callInterface = res.rquestUrl
			let opertionParmes = {
				inputParameter,
				returnParameter,
				operationPicture,
				callInterface,
				responseCode: res.status, //返回状态
				errorMessage: res.message, //错误信息
				isPass: res.status == 200 ? 'Y' : 'N', //是否成功 Y N
				operationType: OPERATION_SCAN
			}
			basPdaOperationLogFn(opertionParmes)
		} catch (error) { }
		if (res.status == 200) {
			if (res.data.total > 0) {
				data.scanInfo = res.data.rows[0];
				// 成品盘点  在扫码的时候 先判断一下物料代码和库位是否有值，如果有值  你要判断下条码本身的物料 或 库位，与选择的物料 库位 是否一致，如果不一致要给提示
				// if (data.materialCode && data.materialCode != res.data.rows[0]?.materialCode) {
				// 	uni.showToast({
				// 		title: t('taskList.scannedMaterial'), icon: "none"
				// 	});
				// 	return
				// }
				// if (data.locationCode && data.locationCode != res.data.rows[0]?.locationCode) {
				// 	uni.showToast({
				// 		title: t('taskList.scannedBarcodeLibrary'), icon: "none"
				// 	});
				// 	return
				// }
				data.locationCode = res.data.rows[0].locationCode
				data.materialCode = res.data.rows[0].materialCode
				inputDialog.value.open()
			} else { // 扫描的数据不存在且后台不报错
				uni.showToast({
					title: t('taskList.barcodeNoInventory'),
					icon: "none"
				});
			}

			data.scanValue = code //扫描的条码
			data.searchType = 1; //条码维度

			selectMaterial() // 去查询条码

		} else {
			uni.showToast({
				title: res.message,
				icon: "none"
			});
		}
	})
}

// 物料代码的选择
const getMaterialClick = (x) => {
	data.materialId = x.id
	data.materialCode = x.materialCode;
	selectMaterial()

}

//库位选择之后赋值给变量
const getLocationClick = (x) => {
	data.locationId = x.id
	data.locationName = x.locationName;
	data.locationCode = x.locationCode;
	selectMaterial()

}

//物料代码查询
const selectMaterial = () => {
	computeSearchType(); //首先计算查询的维度
	getInventoryInfo({ //根据物料代码查询物料详情
		barcode: data.scanValue,
		billCode: data.billCode,
		locationCode: data.locationCode,
		materialCode: data.materialCode
	}).then(res => {
		if (res.status == 200) {
			TotalAndItems(); //查询汇总信息
			switch (data.searchType) {
				case 1:
					data.barcodeData = res.data //条码维度
					data.barcodeData?.forEach((item, index) => {
						if (index != 0) {
							data.value.push('' + index)
						}
					})
					break;
				case 2:
					data.materialData = res.data //物料维度
					data.materialData?.forEach((item, index) => {
						if (index != 0) {
							data.value.push('' + index)
						}
					})
					break;
				case 3:
					data.locationData = res.data //库位维度
					data.locationData?.forEach((item, index) => {
						if (index != 0) {
							data.value.push('' + index)
						}
					})
					break;
			}
		}
	})
}

//计算查询类型
const computeSearchType = () => {
	if (data.scanValue) //条码
	{
		data.searchType = 1;
	} else if (data.locationCode) //库位维度
	{
		data.searchType = 3
	} else {
		data.searchType = 2 //物料维度
	}

}


// 签名信息
data.formData = computed(() => {
	return store.state.fromDataInventory
})

data.buttonText = computed(() => {
	if (data.formData.length) {
		return t('calendar.submit')
	}
	else {
		return t('finishInventory.signature')
	}
})

// 提交接口
const handelCheck = async () => {
	//判断用户是否有提交权限
	let bool = await store.dispatch('checkUser')
	if (!bool) {
		uni.showToast({
			title: t('JsInternational.sorryAuthority'),
			icon: 'none'
		})
		return
	}

	//打开签名页面
	if (!data.formData.length) {
		navigate({
			url: `/pages/finishedInventory/finishedInventorySignature`
		})
		return
	}
	uploadFile()
}
// 上传图片获取开始上传
const uploadFile = () => {
	let isDev = process.env.NODE_ENV === 'development';
	let baseUrl = isDev ? TEST_URL : PROD_URL
	let token = uni.getStorageSync(TOKEN);
	// let str = base64toFile(data.formData,'file')
	let formData = {
		bizId: data.id,
		// file:str,
		bizType: 'wms_checkstock_h'
	}

	uni.showLoading({
		title: t('JsInternational.uploading')
	});
	uni.uploadFile({
		url: baseUrl + '/system/oss/oss-simple', //上传接口
		name: 'file',
		header: {
			// "content-type": "multipart/form-data",
			'token': token
		},
		filePath: data.formData,
		formData: formData,
		success: (uploadFileRes) => {
			uni.hideLoading();
			const back = JSON.parse(uploadFileRes.data);
			if (back.statusCode == 200) {
				// let imgPath = IMG_BASE_URL + back.filePath;
				let imgPath = back.data;
				checkRequest(imgPath)
			} else {
				uni.showToast({
					title: back.message,
					icon: "none"
				});
			}
		},
		fail: () => {
			uni.hideLoading();
			uni.showToast(t('JsInternational.pictureUploading'))
		},
		complete: function () {
			uni.hideLoading();
		}
	});
}
// 生成审核单
const checkRequest = (imgPath) => {
	let parmes = { //盘点审核接口
		id: data.id, // 收料单id
		auditSign: imgPath,
	}
	checkFGStockSubmit(parmes).then(res => {
		try {
			let inputParameter = JSON.stringify(parmes)
			let returnParameter = JSON.stringify(res)
			let operationPicture = '成品盘点'
			let callInterface = res.rquestUrl
			let opertionParmes = {
				inputParameter,
				returnParameter,
				operationPicture,
				callInterface,
				responseCode: res.status, //返回状态
				errorMessage: res.message, //错误信息
				isPass: res.status == 200 ? 'Y' : 'N', //是否成功 Y N
				operationType: OPERATION_COMMIT
			}
			basPdaOperationLogFn(opertionParmes)
		} catch (error) { }
		console.log(res)
		if (res.status == 200) {
			uni.showToast({
				title: t('smashRemoval.submitSuccessfully'),
				icon: 'none',
				complete: () => {
					//清除 缓存总store签名信息
					store.commit('delFormDataInventory')
					uni.navigateBack({
						delta: 1
					});
				}
			})
		} else {
			uni.showToast({
				title: res.message,
				icon: "none"
			});
		}
	})
}

// 页面跳转到查看扫描记录
const clickRight = () => {
	navigate({
		url: `/pages/finishedInventory/scanPanDianDetail?billCode=${data.billCode}&billid=${data.id}`
	})
}

const handelClear = () => {
	data.locationCode = ""
	data.locationName = ""
	data.locationId = null
	selectMaterial()
}

const handelMaterialClear = () => {
	data.materialId = null
	data.materialCode = "";
	selectMaterial()
}


// 点击card的查看
const clickView = (keyword) => {
	navigate({
		url: `/pages/finishedInventory/panDianDetail?keyword=${keyword}&type=${data.searchType}&billCode=${data.billCode}&billid=${data.id}`

	})
}

//点击盘点
const HandCheckPda = (keyword) => {
	switch (data.searchType) {
		case 1: //盘点条码
			var obj = {}
			obj.billCode = data.billCode;
			obj.barcode = keyword;
			obj.materialCode = "";
			obj.locationCode = ""
			obj.ckeckFlag = "Y"
			submitCheckPda(obj);
			break;

		case 2: //盘点物料

			var obj = {}
			obj.billCode = data.billCode;
			obj.barcode = "";
			obj.materialCode = keyword;
			obj.locationCode = ""
			obj.ckeckFlag = "Y"
			submitCheckPda(obj);
			break;

		case 3: //盘点库位

			var obj = {}
			obj.billCode = data.billCode;
			obj.barcode = "";
			obj.materialCode = "";
			obj.ckeckFlag = "Y"
			obj.locationCode = keyword;
			submitCheckPda(obj);
			break;
	}
}


//点击取消盘点
const HandUnCheckPda = (keyword) => {
	switch (data.searchType) {
		case 1: //盘点条码
			var obj = {}
			obj.billCode = data.billCode;
			obj.barcode = keyword;
			obj.materialCode = "";
			obj.locationCode = ""
			obj.ckeckFlag = "N"
			submitCheckPda(obj);
			break;

		case 2: //盘点物料

			var obj = {}
			obj.billCode = data.billCode;
			obj.barcode = "";
			obj.materialCode = keyword;
			obj.locationCode = ""
			obj.ckeckFlag = "N"
			submitCheckPda(obj);
			break;

		case 3: //盘点库位

			var obj = {}
			obj.billCode = data.billCode;
			obj.barcode = "";
			obj.materialCode = "";
			obj.locationCode = keyword;
			obj.ckeckFlag = "N"
			submitCheckPda(obj);
			break;
	}
}

//提交盘点数据
const submitCheckPda = (parmes) => {
	uni.showLoading({
		title: 'loading',
		mask: true
	});
	checkPDA(parmes).then(res => {
		uni.hideLoading();
		try {
			let inputParameter = JSON.stringify(parmes)
			let returnParameter = JSON.stringify(res)
			let operationPicture = '成品盘点'
			let callInterface = res.rquestUrl
			let opertionParmes = {
				inputParameter,
				returnParameter,
				operationPicture,
				callInterface,
				responseCode: res.status, //返回状态
				errorMessage: res.message, //错误信息
				isPass: res.status == 200 ? 'Y' : 'N', //是否成功 Y N
				operationType: OPERATION_COMMIT
			}
			basPdaOperationLogFn(opertionParmes)
		} catch (error) { }
		console.log(res)
		if (res.status == 200) {
			inputDialog.value.close()

			//data.scanValue=""
			data.materialCode = ""
			data.locationCode = ""
			uni.showToast({
				title: t('smashRemoval.submitSuccessfully'),
				icon: 'none',
				complete: () => {
					k3andMESTotal(); //汇总数据也要查询
					selectMaterial() //重新执行查询
				}
			})
		} else {
			uni.showToast({
				title: res.message,
				icon: "none"
			});
		}
	})

}



const cancelFn = () => {
	data.scanInfo = undefined
	inputDialog.value.close()
}


// 扫码弹框确认信息
const scanConfirmFn = () => {
	HandCheckPda(data.scanValue)
}

</script>

<style lang="scss" scoped>
// .card-my{
// 	display: flex;
// 	flex-direction: column;
// }
.addflex {
	display: flex;
	align-items: center;

	.itemflex {
		flex: 1;
	}
}

.distributed {
	display: flex;
	flex-direction: column;
	height: calc(100vh - 200rpx);
	// height: 100vh;
}

.scroll {
	margin-top: 15rpx;
	flex: 1;
	height: 2rpx;
}

.page-bottom-box {
	position: fixed;
}

.addborder {
	border: 1rpx solid #DCDFE6;
	box-sizing: border-box;
	padding: 15rpx;
	margin-bottom: 15rpx;
	border-radius: 8rpx;
}

.input-dialog-itembox {
	padding: 15rpx;
	box-sizing: border-box;
	border: 1rpx solid #DCDFE6;
	margin-bottom: 15rpx;
	border-radius: 8rpx;
}

.input-dialog-item {
	font-size: 24rpx;
}

.input,
.textarea {
	font-size: 24rpx;
}

.iconDelete {
	margin-top: 20rpx;
	height: 100%;
	width: 40rpx;
}

.item-info-title {
	margin-left: 10px;
}


.btnSuccess {
	width: 120rpx;
	height: 40rpx;
	line-height: 40rpx;
	color: #fff;
	background-color: #007aff;
	display: inline-block;
	text-align: center;
	border-radius: 10rpx;
}

.btnError {
	width: 120rpx;
	height: 40rpx;
	line-height: 40rpx;
	color: #fff;
	background-color: red;
	display: inline-block;
	text-align: center;
	border-radius: 10rpx;
}


.btnCancel {
	width: 120rpx;
	height: 40rpx;
	line-height: 40rpx;
	color: #fff;
	background-color: #f08d49;
	display: inline-block;
	text-align: center;
	border-radius: 10rpx;
}

.btnPanDian {
	width: 120rpx;
	height: 40rpx;
	line-height: 40rpx;
	color: #fff;
	background-color: #42b983;
	display: inline-block;
	text-align: center;
	border-radius: 10rpx;
}

.flexRight {

	display: flex;
	flex-direction: row;
	justify-content: flex-end;
}

.card-item-50 {
	flex: 1;
}
</style>
